import java.util.*;
public class CompareTest {
    public static void main(String[] a) {
        TreeMap<Integer, String> treeMap = new TreeMap<>();
        treeMap.put(10, "10G");
        treeMap.put(30, "10G");
        treeMap.put(20, "20G");
        treeMap.put(50, "10G");
        treeMap.put(40, "40G");
        treeMap.put(60, "20G");
        treeMap.put(70, "10G");
        treeMap.put(90, "30G");
        treeMap.put(80, "20G");
        treeMap.put(100,"90G");
        System.out.println("按键升序");
        for(Map.Entry<Integer,String> map:treeMap.entrySet()){
            System.out.println(map.getKey()+":"+map.getValue());
        }
        List<Map.Entry<Integer, String>> list = new ArrayList<>(treeMap.entrySet());
        Collections.sort(list, new VolumeSort());
        System.out.println("按values升序");
        for(Map.Entry<Integer,String> entry : list){
            System.out.println(entry.getKey() + ":"+ entry.getValue());
        }
    }
}
class VolumeSort implements Comparator<Map.Entry<Integer, String>> {
    @Override
    public int compare(Map.Entry<Integer, String> o1, Map.Entry<Integer, String> o2) {
        return o1.getValue().compareTo(o2.getValue());
    }
}